package com.show.mytest;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

public class Test02_Callable {
    public static void main(String[] args) throws Exception {
        // 创建线程池对象,指定最大线程个数为5
        ExecutorService service = Executors.newFixedThreadPool(5);
        // 提交Callable任务 传入需要计算的任务
        Future<Integer> f1 = service.submit(new MyCallable(100));
        Future<Integer> f2 = service.submit(new MyCallable(200));
        // 调用get方法获得返回值
        Integer integer = f1.get();
        Integer integer1 = f2.get();
        // 输出返回值
        System.out.println(integer);    // 5050
        System.out.println(integer1);   // 20100
        // 关闭线程池
        service.shutdown();
    }
}
